package com.qkl.xiatang.app.utils;

import com.qkl.xiatang.app.entity.feed.FeedAllocDetailEntity;
import org.apache.commons.lang3.ObjectUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MsgUtils {

    public static final Integer SUB_TYPE_RECEIVE = 1;

    public static final Integer SUB_TYPE_RECEIVE_NOT = 0;

    public static boolean subTypeReceive(Integer subType){
        return SUB_TYPE_RECEIVE.equals(subType);
    }

    public static String fmtAllocDate(Date allocDate){
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy.MM.dd");
        return fmt.format(allocDate);
    }

    public static boolean subTypeNotReceive(Integer subType){
        return SUB_TYPE_RECEIVE_NOT.equals(subType);
    }

    public static String formatPondNames(List<String> pondNames){
        if(ObjectUtils.isEmpty(pondNames)){
            return "";
        }
        return  formatMessage(pondNames).replaceAll("号","");
    }

    public static String formatMessage(String name){
        List<String> names = new ArrayList<>();
        names.add(name);
        return formatMessage(names);
    }

    public static String formatTitleMessage(List<FeedAllocDetailEntity>  taskList){
        if(ObjectUtils.isEmpty(taskList)){
            return "";
        }
        SimpleDateFormat fmt2 = new SimpleDateFormat("dd日");
        String result = "";
        Date date = null;
        for (int i =0,size = taskList.size(); i < size ;i++ ){
            FeedAllocDetailEntity task = taskList.get(i);
            if(i == 0){
                date = task.getAllocDate();
                result = fmtAllocDate(task.getAllocDate()) + task.getName();
                continue;
            }
            if(date.compareTo(task.getAllocDate()) == 0){
                result = result + task.getName();
                continue;
            }
            String formatDay = fmt2.format(task.getAllocDate());
            if( !result.contains(formatDay)){
                result = result + formatDay;
            }
            result = result + task.getName();
        }
        return result;
    }

    public static String formatMessage(List<String> names){
        if(ObjectUtils.isEmpty(names)){
            return "";
        }
        //return  "[" + String.join(",",names) + "]";
        return  String.join(",",names) ;
    }

}
